package com.tanhua.server.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tanhua.common.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class UserService {
    @Value("${tanhua.sso.url}")
    private String ssoUrl;
    @Autowired
    private RestTemplate restTemplate;
    private static final ObjectMapper MAPPER=new ObjectMapper();
    public User querybytoken(String token) {
       String url = ssoUrl+"/user/"+token;
        try {
            String data = restTemplate.getForObject(url, String.class);
            if(data==null){
                return null;
            }
         return MAPPER.readValue(data, User.class);
        } catch (Exception e) {
           log.error("检验token出错token="+token,e);
        }return null;
    }
}
